package org.apache.sad.core.framework.jaxrpc.handler;

import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.HandlerInfo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * A simple handler for jaxrpc calls for logging soap request, response and fault.
 *
 * @author Anup Dixit
 */
public class DebugHandler extends ClientHandler {

    protected Log log;

    @Override
    public void init(HandlerInfo config) {
    	log = LogFactory.getLog(this.getClass());
    	super.init(config);
    }
    
    /**
     * @see javax.xml.rpc.handler.GenericHandler#handleRequest()
     */
    @Override
    public boolean handleRequest(MessageContext context) {
    	if ( log.isInfoEnabled() )  {
    		log.info(this.prettyLogSoapMessage(context, "Request"));    		
    	}
    	return true;
    }

    /**
     * @see javax.xml.rpc.handler.GenericHandler#handleFault()
     */
    @Override
    public boolean handleFault(MessageContext context) {
    	if ( log.isInfoEnabled() ) {
    		log.info(this.prettyLogSoapMessage(context, "Fault"));    		
    	}
    	return true;
    }

    /**
     * @see javax.xml.rpc.handler.GenericHandler#handleResponse()
     */
    @Override
    public boolean handleResponse(MessageContext context) {
    	if ( log.isInfoEnabled() ) {
    		log.info(this.prettyLogSoapMessage(context, "Response"));    		
    	}
    	return true;
    }

    //No longer needed, obfuscated fields will be configured globally
    //via a ObfuscationConfiguration bean.
    @Deprecated 
	protected String[] getObfuscatedFields() {
    	return new String[0];    	
    }    
}
